home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / OldPatch / MPLockPubPatch.c_4.53 < prev    next >
Text File  |  1998-10-07  |  8KB  |  330 lines

  1. #define DEBUG//                                      (VER.REV.1)
  2. #define ADD_DEBUG_CODE//                             (VER.REV.1)
  3. #include <debug.h>//                                 (VER.REV.1)
  4. //                                                   (VER.REV.1)
  5. #include "MP.h"//                                    (VER.REV.1)
  6. #include <extras/macros/exec.h>
  7. struct SignalSemaphore LockPubSem;
  8.  
  9. extern struct Process  *MPTask;
  10. extern BYTE   PublicSignal;
  11.  
  12.  
  13. extern struct MPSem *MPSem;
  14. extern UBYTE   ModePro[];
  15.  
  16. 131extern struct Screen * __asm (*OldLockPubScreen)(register __a0 UBYTE *Name,
  17.                                                register __a6 struct Library *);
  18. extern void __asm (*OldUnlockPubScreen)(register __a0 UBYTE *Name,
  19.                                         register __a1 struct Screen *,
  20.                                         register __a6 struct Library *);
  21.  
  22.  
  23. struct Screen * __saveds __asm NewLockPubScreen(register __a0 UBYTE *Name,
  24.                                                 register __a6 struct IntuitionBase *IBase)
  25. {
  26.   struct OpenNode *on;
  27.   struct Screen *scr, *ps;
  28.   struct DefaultNode *dnode;
  29.   LONG button;
  30.   char tnamebuffer[52];
  31.   char *tname;
  32.   ULONG stackid=0xc0de0020;
  33.   
  34.   tname=SetupTaskName(tnamebuffer,", LPS",50);
  35.  
  36. #ifdef ADD_DEBUG_CODE
  37.   if(MPSem->Debug)
  38.   {
  39.     DKP("LockPubScreen(%s)\n",Name);
  40.   }
  41. #endif
  42.  
  43.   ps=0;
  44.  
  45.   // 4.53 @11 Should keep duplicate pubscreens from being created in a race condition
  46.   ObtainSemaphoreShared(&MPSem->ListSem); 
  47.   ObtainSemaphore(&MPSem->NodeSem);
  48.  
  49.   if(scr=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  50.   {
  51.     DEBUG_CODE(DKP("  RV=0x%08lx\n",ps););
  52.  
  53.     SetTaskName(tname);
  54.     
  55.     ReleaseSemaphore(&MPSem->NodeSem);    
  56.     ReleaseSemaphore(&MPSem->ListSem);
  57.  
  58.     return(scr);
  59.   }
  60.   else
  61.   {
  62.     ObtainSemaphore(&LockPubSem);
  63.     if(scr=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  64.     {
  65.       DEBUG_CODE(DKP("  RV=0x%08lx\n",ps););
  66.  
  67.       SetTaskName(tname);
  68.  
  69.       ReleaseSemaphore(&LockPubSem);      
  70.       ReleaseSemaphore(&MPSem->NodeSem);    
  71.       ReleaseSemaphore(&MPSem->ListSem);
  72.   
  73.       return(scr);
  74.     }
  75.     else    
  76.     {
  77.       if(strcmp("Workench",Name)) // Can't f with Workbench!
  78.       {
  79.         // 4.53 moved above
  80. //      ObtainSemaphoreShared(&MPSem->ListSem); 
  81. //      ObtainSemaphore(&MPSem->NodeSem);
  82.         
  83.         if(dnode=FindDNode(&MPSem->PromotionList[PL_PUBLICSCREENS],Name))
  84.         {
  85.           if(dnode->Flags & DNF_NEVER_PROMOTE)
  86.             dnode=0;
  87.           else
  88.             dnode=DupDNode(dnode);
  89.   
  90.           ReleaseSemaphore(&MPSem->NodeSem);    
  91.         }
  92.         else
  93.         {
  94.           ReleaseSemaphore(&MPSem->NodeSem);    
  95.           if(MPSem->CatchPubScreens)
  96.           {
  97.             if(button=EZReq(0,0,ModePro,GetString(MSG_NEW_PUBSCREEN),GetString(MSG_NEW_PUBSCREEN_BUTTONS),(ULONG)Name))
  98.             {
  99.               if(dnode=AllocDefaultNode(Name))
  100.               {
  101.                 dnode->Type=PL_PUBLICSCREENS;
  102.                 dnode->ModeSelect=2;
  103.                 CloneWB(dnode);
  104.                 dnode=ForceEdit(dnode);
  105.               }   
  106.             }
  107.           }
  108.         }
  109.         
  110.         ReleaseSemaphore(&MPSem->ListSem);
  111.         
  112.         ps=0;
  113.         
  114.         if(dnode)
  115.         {
  116.           FreeVec(dnode->PubName);
  117.           dnode->PubName=Name;
  118.           dnode->PubOptions=1;
  119.       
  120.           if(scr=OpenScreenTags(0, SA_Title                 ,Name,
  121.                                    SA_ModeProNode           ,dnode,
  122.                                    TAG_DONE))
  123.           {
  124.             if(ps=OldLockPubScreen(Name,(struct Library *)IntuitionBase))
  125.             {
  126.               //4.53 @8 now clears ON_OPEN flag
  127.               ObtainSemaphore(&MPSem->OpenListSem);
  128.               if(on=FindOpenNode(ps))
  129.               {
  130.                 // clear the open flag so MP can close the screen
  131.                 on->Flags&=(~ON_OPEN);
  132.               }
  133.               ReleaseSemaphore(&MPSem->OpenListSem);
  134. //          CloseScreen(scr);
  135.             }
  136.           }
  137.           
  138.           dnode->PubName=0;
  139.           dnode->PubOptions=0;
  140.           
  141.           FreeDNode(dnode);
  142.         }      
  143.       }
  144.       ReleaseSemaphore(&LockPubSem);
  145.     }
  146.   }
  147.  
  148.   DEBUG_CODE(DKP("  RV=0x%08lx\n",ps););
  149.  
  150.   SetTaskName(tname);
  151.   
  152.   return(ps);
  153. }                          
  154.  
  155.  
  156.  
  157. // 4.53 @9 New patch
  158. void __saveds __asm NewUnlockPubScreen(register __a0 UBYTE *Name, 
  159.                                        register __a1 struct Screen *Scr,
  160.                                        register __a6 struct Library *IBase)
  161. {
  162.   BOOL signal=0;
  163.   struct List *plist;
  164.   struct PubScreenNode *psn;
  165.   struct OpenNode *on;
  166.   char tnamebuffer[52];
  167.   char *tname;
  168.   ULONG stack2=0xc0de0021;
  169.   
  170.   tname=SetupTaskName(tnamebuffer,", ULPS",50);
  171.  
  172. #ifdef ADD_DEBUG_CODE
  173.   if(MPSem->Debug)
  174.   {
  175.     DKP("UnLockPubScreen(%s,0x%08lx)\n",Name,Scr);
  176.   }
  177. #endif
  178.  
  179.   OldUnlockPubScreen(Name,Scr,IBase);
  180.  
  181.   // signal MP, birdie kludge
  182.   Signal((struct Task *)MPTask,1<<PublicSignal);
  183.   
  184.   SetTaskName(tname);
  185. }
  186.  
  187. /*
  188. struct Screen * __saveds __asm ModeProPubScreen(register __a0 UBYTE *Name)
  189. {
  190.   struct Screen *ps;
  191.   struct DefaultNode *dnode;
  192.   LONG button;
  193.   char tnamebuffer[52];
  194.   char *tname;
  195.   ULONG stack2=0xc0de0022;
  196.   
  197.   tname=SetupTaskName(tnamebuffer,", MPPS",50);
  198.  
  199.   if(strcmp("Workench",Name)) // Can't f with Workbench!
  200.   {
  201.     ObtainSemaphoreShared(&MPSem->ListSem); 
  202.     ObtainSemaphore(&MPSem->NodeSem);
  203.     
  204.     if(dnode=FindDNode(&MPSem->PromotionList[PL_PUBLICSCREENS],Name))
  205.     {
  206.       if(dnode->Flags & DNF_NEVER_PROMOTE)
  207.         dnode=0;
  208.       else
  209.         dnode=DupDNode(dnode);
  210.        ReleaseSemaphore(&MPSem->NodeSem);    
  211.     }
  212.     else
  213.     {
  214.       ReleaseSemaphore(&MPSem->NodeSem);    
  215.       if(MPSem->CatchPubScreens)
  216.       {
  217.         if(button=EZReq(0,0,ModePro,GetString(MSG_NEW_PUBSCREEN),GetString(MSG_NEW_PUBSCREEN_BUTTONS),(ULONG)Name))
  218.         {
  219.           if(dnode=AllocDefaultNode(Name))
  220.           {
  221.             dnode->Type=PL_PUBLICSCREENS;
  222.             dnode->ModeSelect=2;
  223.             CloneWB(dnode);
  224.             dnode=ForceEdit(dnode);
  225.           }   
  226.         }
  227.       }
  228.     }
  229.     
  230.     ReleaseSemaphore(&MPSem->ListSem);
  231.     
  232.     ps=0;
  233.     
  234.     if(dnode)
  235.     {
  236.       FreeVec(dnode->PubName);
  237.       dnode->PubName=Name;
  238.       dnode->PubOptions=1;
  239.   
  240.       if(scr=OpenScreenTags(0, SA_Title                 ,Name,
  241.                                SA_ModeProNode           ,dnode,
  242.                                TAG_DONE))
  243.       {
  244.         ps=OldLockPubScreen(Name,(struct Library *)IntuitionBase);
  245.       
  246.         CloseScreen(scr);
  247.       }
  248.       
  249.       dnode->PubName=0;
  250.       dnode->PubOptions=0;
  251.       
  252.       FreeDNode(dnode);
  253.     }      
  254.   }
  255.  }
  256.   
  257.   SetTaskName(tname);
  258.   
  259.   return(ps);
  260. }  
  261. */
  262.  
  263.  
  264.  
  265.  
  266. /*
  267.  
  268. */
  269.  
  270. /*
  271. struct Screen * __saveds __asm NewLockPubScreen(register __a0 UBYTE *Name,
  272.                                                 register __a6 struct IntuitionBase *IBase)
  273. {
  274.   struct Screen *ps;
  275.   struct DefaultNode *dnode;
  276.   LONG button;
  277.   char tnamebuffer[52];
  278.   char *tname;
  279.   ULONG stack2=0xc0de0020;
  280.   
  281.   tname=SetupTaskName(tnamebuffer,", LPS",50);
  282.  
  283.  
  284.  
  285. #ifdef ADD_DEBUG_CODE
  286.   if(MPSem->Debug)
  287.   {
  288.     DKP("LockPubScreen(%s)\n",Name);
  289.   }
  290. #endif
  291.  
  292.   ps=0;
  293.   
  294.   if(0==(ps=OldLockPubScreen(Name,(struct Library *)IntuitionBase))) 
  295.   { // if it fails
  296.     if(strcmp("Workench",Name)) // Can't f with Workbench!
  297.     {
  298.       // 4.53 rewritten so that ModePro opens the pubscreen not the calling task
  299.       struct MsgPort *mport;
  300.       struct MPMessage mpm;
  301.       
  302.       if(mport=CreateMsgPort())
  303.       {
  304.         mpm.mp_Message.mn_ReplyPort=mport;
  305.         mpm.mp_Message.mn_Length=sizeof(mpm);
  306.         mpm.Command = MP_PUBSCREEN;
  307.         mpm.Code    = 0; // Open/Lock
  308.         mpm.Data    = Name;
  309.  
  310.         PutMsg(MPSem->DaemonPort,(struct Message *)&mpm);
  311.         WaitForReply((struct Message *)&mpm);
  312.         
  313.         ps=OldLockPubScreen(Name);
  314.  
  315.         mpm.Code    = 1; // Unlock
  316.  
  317.         PutMsg(MPSem->DaemonPort,(struct Message *)&mpm);
  318.         WaitForReply((struct Message *)&mpm);
  319.         
  320.         DeleteMsgPort(mport);
  321.       }
  322.     }
  323.   }
  324.   
  325.   SetTaskName(tname);
  326.   
  327.   return(ps);
  328. }  
  329.  
  330. */